<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Common\Model;
use Think\Model;


class ChsiModel extends Model{

    /* 用户模型自动完成 */
    protected $_auto = array(
        array('updatetime', NOW_TIME),
        array('status', 1, self::MODEL_INSERT),
    );

    public function UpdateXueXin($uid,$token,$update=false){

        $data = $this->where('uid='.$uid)->find();
        if(!empty($data)){
            if($update==false){
                return $data;
            }
        }
        $api = new \Common\Extend\Api\ApiClient();
        $api = $api->credit();
        $api->method       = 'api.common.getResult';
        $api->token        = $token;
        $api->bizType       ='education';
        $info =$api->Send('post','json')->data();
        $studentStatusInfo  = $info['data']['studentStatusInfo'];
        $educationInfo      = $info['data']['educationInfo'];
        $data = [
          'uid'                 =>      $uid,
          'token'               =>      $token,
          'name'                =>      $studentStatusInfo['name'],
          'sex'                 =>      $studentStatusInfo['sex'],
          'personalPhotos'      =>      $studentStatusInfo['personalPhotos'],
          'nation'              =>      $studentStatusInfo['nation'],
          'dateBirth'           =>      $studentStatusInfo['dateBirth'],
          'identityNo'          =>      $studentStatusInfo['identityNo'],
          'stuNumber'           =>      $studentStatusInfo['stuNumber'],
          'candidateNumber'     =>      $studentStatusInfo['candidateNumber'],
          'schoolName'          =>      $studentStatusInfo['schoolName'],
          'branch'              =>$studentStatusInfo['branch'],
          'department'          =>$studentStatusInfo['department'],
          'specialitieName'     =>$studentStatusInfo['specialitieName'],
          'classes'             =>$studentStatusInfo['classes'],
          'arrangement'         =>$studentStatusInfo['arrangement'],
          'educationalSystem'   =>$studentStatusInfo['educationalSystem'],
          'educationType'       =>$studentStatusInfo['educationType'],
          'learningForm'        =>$studentStatusInfo['learningForm'],
          'timeEnrollment'      =>$studentStatusInfo['timeEnrollment'],
          'dateGraduation'      =>$studentStatusInfo['dateGraduation'],
          'enrollmentStatus'    =>$studentStatusInfo['enrollmentStatus'],
          'info_name'           =>$educationInfo['name'],
          'info_sex'            =>$educationInfo['sex'],
          'info_identityNo'     =>$educationInfo['identityNo'],
          'info_personalPhotos' =>$educationInfo['personalPhotos'],
          'info_dateBirth'      =>$educationInfo['dateBirth'],
          'info_timeEnrollment' =>$educationInfo['timeEnrollment'],
          'info_dateGraduation' =>$educationInfo['dateGraduation'],
          'info_educationType'  =>$educationInfo['educationType'],
          'info_arrangement'    =>$educationInfo['arrangement'],
          'info_schoolName'     =>$educationInfo['schoolName'],
          'info_schoolDistrict' =>$educationInfo['schoolDistrict'],
          'info_specialitieName'=>$educationInfo['specialitieName'],
          'info_learningForm'   =>$educationInfo['learningForm'],
          'info_certificateNumber'  =>$educationInfo['certificateNumber'],
          'info_graduationStatus'   =>$educationInfo['graduationStatus'],
          'updatetime'              =>time(),
          'status'                  =>0,
        ];

        if(empty($update)){
            $User = M("Chsi");
            $User->add($data);
        }else{
            $this->where('uid='.$uid)->save($data);
        }
        return $data;
    }



}
